package com.lgkj.ui.userinfo;

import android.content.Intent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.lgkj.R;
import com.lgkj.ui.BaseActivity;
import com.lgkj.utils.CommonConstant;
import com.lgkj.utils.HttpUtils;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/11/22 0022.
 */

public class TiXianActivity extends BaseActivity {
    @BindView(R.id.tv_tips)
    TextView tvTips;
    @BindView(R.id.et_price)
    EditText etPrice;
    @BindView(R.id.et_zfb)
    EditText etZfb;
    @BindView(R.id.et_wx)
    EditText etWx;
    @BindView(R.id.et_yhk_name)
    EditText etYhkName;
    @BindView(R.id.et_yhk_id)
    EditText etYhkId;
    @BindView(R.id.et_yhk_adress)
    EditText etYhkAdress;
    @BindView(R.id.tv_toatla)
    TextView tvTotla;
    @BindView(R.id.et_zfb_name)
    EditText etZfbName;

    @Override
    public int getLayoutId() {
        return R.layout.activity_tixian;
    }

    @Override
    public void initView() {
        setTitle("我的收益");
    }

    @Override
    public void initData() {
        showDiaLog("正在获取");
        Map<String, String> map = new HashMap<>();
        map.put("access_token", getToken());
        HttpUtils.postHttp(map, CommonConstant.getTotalMoney, new HttpUtils.HttpCallBack() {
            @Override
            public void successHttp(JSONObject jsonObject, int id) {
                dismissDiaLog();
                if (jsonObject.optInt("code") == 0) {
                    tvTotla.setText("我的总收益:" + jsonObject.optString("data"));
                } else {
                    toastLong(jsonObject.optString("msg"), 0);
                }
            }

            @Override
            public void errorHttp(String msg) {
                dismissDiaLog();
            }
        });
    }


    private void save() {
        showDiaLog("正在提交");
        Map<String, String> map = new HashMap<>();
        map.put("access_token", getToken());
        map.put("money", etPrice.getText().toString());
        map.put("ali_account", etZfb.getText().toString() + "," + etZfbName.getText().toString());
        map.put("wx_account", etWx.getText().toString());
        map.put("blank_name", etYhkName.getText().toString());
        map.put("blank_account", etYhkId.getText().toString());
        map.put("blank_open_address", etYhkAdress.getText().toString());
        HttpUtils.postHttp(map, CommonConstant.applyCashBack, new HttpUtils.HttpCallBack() {
            @Override
            public void successHttp(JSONObject jsonObject, int id) {
                dismissDiaLog();
                if (jsonObject.optInt("code") == 0) {
                    finish();
                    toastLong("申请提现成功，请等待客服人员打款", 0);
                } else {
                    toastLong(jsonObject.optString("msg"), 0);
                }
            }

            @Override
            public void errorHttp(String msg) {
                dismissDiaLog();
            }
        });
    }

    @OnClick({R.id.ll_tips, R.id.btn_save})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_save:
                save();
                break;
            case R.id.ll_tips:
                startsActivity(new Intent(TiXianActivity.this, IncomeActivity.class));
                break;
        }
    }
}
